<template>
  <div class="table-container">
    <div class="special-title">{{ currentDate }} A股交易量排行榜</div>
    <div class="excel-container">
      <el-table
          :data="wxList"
          style="width: 100%;margin-bottom: 20px;overflow-x: auto"
          class="custom-table"
          row-class-name="table-row"
      >
        <el-table-column prop="num" label="序号" sortable class="column-style"></el-table-column>
        <el-table-column prop="vol" label="交易量" sortable class="column-style amount-column">
          <template slot-scope="scope">
            <span class="amount-value">
              {{ (scope.row.vol / 10000).toFixed(2) }}

            </span>
            <span class="unit">万手</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="股票名称" sortable class="column-style"></el-table-column>
        <el-table-column prop="tsCode" label="股票代码" sortable class="column-style"></el-table-column>
        <el-table-column prop="industry" label="行业" sortable class="column-style"></el-table-column>
        <el-table-column prop="open" label="开盘价/元" sortable class="column-style"></el-table-column>
        <el-table-column prop="price" label="收盘价/元" sortable class="column-style">
          <template slot-scope="scope">
            {{ scope.row.price?.toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column prop="pctChg" label="涨幅" sortable class="column-style">
          <template slot-scope="scope">
            <span class="amount-value" :class="getChangeClass(scope.row.pctChg)">
                {{ formatPercentage(scope.row.pctChg) }}
<!--                <span class="unit">%</span>-->
            </span>
          </template>
        </el-table-column>
      </el-table>

    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      wxList: [],
      currentDate: '',
      num: 1
    }
  },
  methods: {
    // 新增方法：格式化百分比显示
    formatPercentage(value) {
      if (value === null || value === undefined) return '--'
      return `${value >= 0 ? '' : '-'}${Math.abs(value).toFixed(2)}`
    },
    // 新增方法：获取样式类名
    getChangeClass(value) {
      if (value > 0) return 'positive'
      if (value < 0) return 'negative'
      return 'neutral'
    },


    simList() {
      axios({
        method: 'get',
        url: '/api/info/base/vol/list',
      }).then(res => {
        this.wxList = res.data.data.map(v => {
          v.num = this.num++;
          return v
        })
      })
    },
    getFormattedDate() {
      const today = new Date()
      const year = today.getFullYear()
      const month = String(today.getMonth() + 1).padStart(2, '0')
      const day = String(today.getDate()).padStart(2, '0')
      this.currentDate = `${year}年${month}月${day}日`
    }
  },
  created() {
    this.getFormattedDate()
    this.simList()
  }
}
</script>

<style scoped>
.table-container {
  background: linear-gradient(135deg, #fff9e6 0%, #f5e6cc 100%);
  padding: 1.4rem;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(168,132,82,0.1);
  font-family: '微软雅黑', '思源黑体', sans-serif;
}

.special-title {
  color: #4a3a2a;
  position: relative;
  padding-bottom: 0.5rem;
  font-size: 2.8rem !important;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: 1px 1px 2px rgba(168,132,82,0.1);
  margin-bottom: 0.3rem !important;
  margin-top: 0rem !important;
  text-align: center;
}

::v-deep .custom-table th {
  background: linear-gradient(180deg, #d4c19c 0%, #b89f7d 100%);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-right: 1px solid rgba(255,255,255,0.15);
}

::v-deep .custom-table td {
  background: rgba(255,253,248,0.98);
  color: #4a3a2a;
  font-size: 1.4rem;
  border-bottom: 1px solid #ece6db;
  transition: all 0.25s ease;
}

::v-deep .el-table__cell .cell {
  font-family: 'Roboto Mono', monospace;
  font-weight: 500;
  text-align: center !important;
}

.excel-container {
  margin: 0 5%;  /*外边距*/
  border: 2px solid #d4c19c;
  border-radius: 10px;
  background: #fff;
  /*box-shadow: inset 0 0 12px rgba(189,173,148,0.1);*/
}

::v-deep .amount-column .cell {
  padding-right: 1.2rem !important;
  text-align: right !important;
}

.amount-value {
  font-family: 'Roboto Mono', monospace;
  font-weight: 600;
  color: #4a3a2a;
  position: relative;
  padding-right: 0em;

}

.unit {
  font-size: 0.9em;
  color: #ec790b;
  position: absolute;
  bottom: 0em;
  line-height: 2.2;

}




.positive { color: #ec2626 !important; }
.negative { color: #1ac50f !important; }

::v-deep .el-table__row {
&:hover td {
   background: #f5ede0 !important;
   transform: scale(1.005);
   box-shadow: 0 2px 8px rgba(168,132,82,0.08);
 }
}

::v-deep [class*="el-table__column--sortable"] .cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

::v-deep .amount-column .cell {
  justify-content: flex-end;
}
</style>
